package com.hangzhou.welbeing.welbeinginstrument.activity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.adapter.ProfilePageFocusedAdapter;
import com.hangzhou.welbeing.welbeinginstrument.adapter.SimilarProfilePageFocusedAdapter;
import com.hangzhou.welbeing.welbeinginstrument.base.MyApplication;
import com.hangzhou.welbeing.welbeinginstrument.bean.AttentionPostBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.CancelAttentionPostBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.ClickcollectBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.CommentsBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.ExposePostBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.PostCommentsBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.PraiseBean;
import com.hangzhou.welbeing.welbeinginstrument.bean.TipOffPostBean;
import com.hangzhou.welbeing.welbeinginstrument.config.RBConstants;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;
import com.hangzhou.welbeing.welbeinginstrument.tool.GlideCircleTransform;
import com.hangzhou.welbeing.welbeinginstrument.tool.GlideImageLoader;
import com.hangzhou.welbeing.welbeinginstrument.utils.DialogUtil;
import com.hangzhou.welbeing.welbeinginstrument.utils.OnItemSelectedListener;
import com.hangzhou.welbeing.welbeinginstrument.utils.Utils;
import com.youth.banner.Banner;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.sharesdk.onekeyshare.OnekeyShare;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 时间 2017 年 09 月 11.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.pregnant.welbeing_pregnant.fragement
 * 工程名 welbeing_pregnant
 */
public class SimilarProfilePageFocusedActivity extends Activity {
    private static final String TAG ="SimilarProfilePageFocusedActivity" ;
    @Bind(R.id.activity_similar_profile_page_focused_iv_return)
    ImageView activitySimilarProfilePageFocusedIvMore01;
    @Bind(R.id.activity_similar_profile_page_focused_rl_iv_head_portrait)
    ImageView activitySimilarProfilePageFocusedRlIvHeadPortrait;
    @Bind(R.id.activity_similar_profile_page_focused_rl_tv_concrete_circle)
    TextView activitySimilarProfilePageFocusedRlTvConcreteCircle;
    @Bind(R.id.activity_similar_profile_page_focused_tv_attention)
    TextView activitySimilarProfilePageFocusedTvAttention;
    @Bind(R.id.activity_similar_profile_page_focused_ll_attention)
    LinearLayout activitySimilarProfilePageFocusedLlAttention;
    @Bind(R.id.activity_similar_profile_page_focused_tv_titiles)
    TextView activitySimilarProfilePageFocusedTvTitiles;
    @Bind(R.id.activity_similar_profile_page_focused_tv_content)
    TextView activitySimilarProfilePageFocusedTvContent;
    @Bind(R.id.activity_similar_profile_page_focused_iv_next_pager)
    ImageView activitySimilarProfilePageFocusedIvNextPager;
    @Bind(R.id.activity_similar_profile_page_focused_tv_commentaries)
    TextView activitySimilarProfilePageFocusedTvCommentaries;
    @Bind(R.id.activity_similar_profile_page_focused_rl_commentaries)
    RelativeLayout activitySimilarProfilePageFocusedRlCommentaries;
    @Bind(R.id.activity_similar_profile_page_focused_ecyclerView)
    RecyclerView activitySimilarProfilePageFocusedEcyclerView;
    @Bind(R.id.activity_similar_profile_page_focused_tv_post_circle_date)
    TextView activitySimilarProfilePageFocusedTvPostCircleDate;
    @Bind(R.id.activity_similar_profile_page_focused_banner)
    Banner activitySimilarProfilePageFocusedBanner;
    @Bind(R.id.activity_similar_profile_page_focused_iv_right)
    ImageView activitySimilarProfilePageFocusedIvRight;

    @Bind(R.id.activity_similar_profile_page_focused_rl_praise)
    RelativeLayout activitySimilarProfilePageFocusedRlPraise;
    @Bind(R.id.activity_similar_profile_page_focused_iv_praise)
    ImageView activitySimilarProfilePageFocusedIvPraise;
    @Bind(R.id.activity_similar_profile_page_focused_tv_praise_bumber)
    TextView activitySimilarProfilePageFocusedTvPraisepraiseBumber;


    @Bind(R.id.activity_similar_profile_page_focused_rl_Banner)
    RelativeLayout activitySimilarProfilePageFocusedRlBanner;


    @Bind(R.id.activity_similar_profile_page_focused_rl_comments)
    RelativeLayout activitySimilarProfilePageFocusedRlComments;
    @Bind(R.id.activity_similar_profile_page_focused_iv_comments)
    ImageView activitySimilarProfilePageFocusedIvComments;
    @Bind(R.id.activity_similar_profile_page_focused_tv_comments_bumber)
    TextView activitySimilarProfilePageFocusedTvCommentsBumber;



    @Bind(R.id.activity_similar_profile_page_focused_rl_favorite)
    RelativeLayout activitySimilarProfilePageFocusedRlFavorite;
    @Bind(R.id.activity_similar_profile_page_focused_iv_favorite)
    ImageView activitySimilarProfilePageFocusedIvFavorite;
    @Bind(R.id.activity_similar_profile_page_focused_tv_favorite_bumber)
    TextView activitySimilarProfilePageFocusedTvFavoriteBumber;



    @Bind(R.id.activity_similar_profile_page_focused_ll_is_visition)
    LinearLayout activitySimilarProfilePageFocusedLlIsVisition;
    @Bind(R.id.activity_similar_profile_page_focused_ll_04)
    LinearLayout activitySimilarProfilePageFocusedLl04;

    @Bind(R.id.activity_similar_profile_page_focused_ll_commentaries)
    LinearLayout activitySimilarProfilePageFocusedLlCommentaries;
    @Bind(R.id.activity_similar_profile_page_focused_bt_sand_commentaries)
    Button activitySimilarProfilePageFocusedBSandCommentaries;
    @Bind(R.id.activity_similar_profile_page_focused_et_commentaries_content)
    EditText activitySimilarProfilePageFocusedEtCommentariesContent;
    private ProfilePageFocusedAdapter profilePageFocusedAdapter;
    private List<PostCommentsBean.DataBean> mlist;
    private String po_id;
    private SimilarProfilePageFocusedAdapter similarProfilePageFocusedAdapter;
    private String id1;


    private List<String> images = new ArrayList<>();
    private String cus_id;



    private View inflate;
    private TextView choosePhoto;
    private TextView takePhoto;
    private Dialog dialog;

    private int p1 = 1;
    private int lastVisibleItem;
    private int pareInt;
    private int pareInt_01;

    private String[] items = {"色情/辱骂", "广告骚扰", "政治", "其他"};
    int mWidth;
    private LinearLayout ll_tip_off;
    private LinearLayout ll_share;
    private String count;
    private int intent_01;
    private String po_url;
    private String po_name;
    private String content;
    private String cus_logo;
    private String addtime;
    private String cus_name;
    private String state;
    private String lCount;
    private String lstate;
    private String col;
    private String hits_like;
    private boolean flag_04 = true ;
    private boolean flag_01 = true ;
    private int pareInt_02;
    private int pareInt_03;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_similar_profile_page_focused);
        ButterKnife.bind(this);
       // ShareSDK.initSDK(this);
        Utils.setStatusBar(this,false,false);
        Utils.setStatusTextColor(true,this);


       Intent intent =  getIntent();
        po_id = intent.getStringExtra("po_id");
       // po_url = intent.getStringExtra("po_url");
        po_name = intent.getStringExtra("po_name");
        content = intent.getStringExtra("content");
        cus_logo = intent.getStringExtra("cus_logo");
        addtime = intent.getStringExtra("addtime");
        cus_name = intent.getStringExtra("cus_name");
        state = intent.getStringExtra("state");
        lCount = intent.getStringExtra("lCount");
        lstate = intent.getStringExtra("lstate");
        count = intent.getStringExtra("count");
        col = intent.getStringExtra("col");
        hits_like = intent.getStringExtra("hits_like");
        cus_id = intent.getStringExtra("cus_id");

        intent_01 = Integer.parseInt(count);
        if(po_url == null || po_url.equals("")){
            activitySimilarProfilePageFocusedRlBanner.setVisibility(View.GONE);
        }else{
            /**-------广告图--------*/
            String[] arr = po_url.split(",");
            if(arr.length > 0 ){
                for (String s : arr) {
                    images.add(RBConstants.SERVER_URL+"/Public/Uploads/"+s);
                }
                activitySimilarProfilePageFocusedBanner.setImages(images).setImageLoader(new GlideImageLoader()).start();
            }else {
                activitySimilarProfilePageFocusedRlBanner.setVisibility(View.GONE);
            }
        }
        activitySimilarProfilePageFocusedTvCommentsBumber.setText(count);
        activitySimilarProfilePageFocusedTvFavoriteBumber.setText(col);
        Glide.with(this).load(RBConstants.SERVER_URL+"/Public/Uploads/"+ cus_logo).transform(new GlideCircleTransform(this)).into(activitySimilarProfilePageFocusedRlIvHeadPortrait);
        activitySimilarProfilePageFocusedRlTvConcreteCircle.setText(cus_name);
        activitySimilarProfilePageFocusedTvPostCircleDate.setText(addtime);
        if(state != null){
            if(state.equals("0")){
                activitySimilarProfilePageFocusedTvAttention.setText("关注");
            }else if(state.equals("1")){
                activitySimilarProfilePageFocusedTvAttention.setText("已关注");
            }else if(state.equals("2")){
                activitySimilarProfilePageFocusedTvAttention.setText("互相关注");
            }
        }

        activitySimilarProfilePageFocusedTvTitiles.setText(po_name);
        activitySimilarProfilePageFocusedTvContent.setText(content);
        activitySimilarProfilePageFocusedTvCommentaries.setText("共"+ count +"条评论");


        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        activitySimilarProfilePageFocusedEcyclerView.setLayoutManager(layoutManager);

        initPostComments(p1, po_id);
        initData();
    }

    private void showShare() {
        OnekeyShare oks = new OnekeyShare();
        //关闭sso授权
        oks.disableSSOWhenAuthorize();

        // 分享时Notification的图标和文字  2.5.9以后的版本不调用此方法
        //oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
        oks.setTitle("");
        // titleUrl是标题的网络链接，仅在人人网和QQ空间使用 //"http://sharesdk.cn"
        oks.setTitleUrl(RBConstants.SERVER_URL+RBConstants.SHARED_SDK+po_id+"");
        // text是分享文本，所有平台都需要这个字段
        oks.setText(RBConstants.SERVER_URL+RBConstants.SHARED_SDK+po_id+"");
        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
        oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
        // url仅在微信（包括好友和朋友圈）中使用
        oks.setUrl(RBConstants.SERVER_URL+RBConstants.SHARED_SDK+po_id+"");
        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
        oks.setComment("");
        // site是分享此内容的网站名称，仅在QQ空间使用
        oks.setSite(getString(R.string.app_name));
        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
        oks.setSiteUrl(RBConstants.SERVER_URL+RBConstants.SHARED_SDK+po_id+"");

        // 启动分享GUI
        oks.show(this);
    }
    /**
     * @desc 举报弹框
     * */
    private void initData() {
        DisplayMetrics dm = new DisplayMetrics();
        this.getWindowManager().getDefaultDisplay().getMetrics(dm);
        mWidth = dm.widthPixels;
    }
    private OnItemSelectedListener onIllegalListener = new OnItemSelectedListener() {
        @Override
        public void getSelectedItem(String content) {
            //Toast.makeText(SimilarProfilePageFocusedActivity.this, content, Toast.LENGTH_SHORT).show();
           exposePost(po_id,content);
        }
    };
    private void showDialog() {
        DialogUtil.showItemSelectDialog(SimilarProfilePageFocusedActivity.this, mWidth
                , onIllegalListener
                , "色情/辱骂"
                , "广告骚扰"
                , "政治"
                , "其他");//可填添加任意多个Item呦
    }


    @OnClick({R.id.activity_similar_profile_page_focused_iv_return, R.id.activity_similar_profile_page_focused_rl_iv_head_portrait,
            R.id.activity_similar_profile_page_focused_ll_attention, R.id.activity_similar_profile_page_focused_rl_commentaries,
            R.id.activity_similar_profile_page_focused_rl_praise,R.id.activity_similar_profile_page_focused_rl_comments,
            R.id.activity_similar_profile_page_focused_rl_favorite,R.id.activity_similar_profile_page_focused_bt_sand_commentaries,
           R.id.activity_similar_profile_page_focused_tv_attention,
            R.id.activity_similar_profile_page_focused_iv_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_similar_profile_page_focused_iv_return:
                finish();

                break;
            case R.id.activity_similar_profile_page_focused_rl_iv_head_portrait: //
             /*   Intent intent3  =  new Intent(SimilarProfilePageFocusedActivity.this,MyPostingOnCircleActivity.class);
                startActivity(intent3);*/
                break;
            case R.id.activity_similar_profile_page_focused_ll_attention:  //关注
               /* Intent intent = new Intent(SimilarProfilePageFocusedActivity.this, PersonalArticlesActivity.class);
                startActivity(intent);*/
                String attention =  activitySimilarProfilePageFocusedTvAttention.getText().toString().trim();
                if(attention.equals("关注")){
                    //添加关注
                    addAttentionPost(cus_id);
                }else if(attention.equals("已关注")){
                    //取消关注
                    cancelAttentionPost(cus_id);
                }else if(attention.equals("互相关注")){
                    //取消关注
                    cancelAttentionPost(cus_id);
                }

                break;
            case  R.id.activity_similar_profile_page_focused_rl_comments: //评论

                Intent intent = new Intent(SimilarProfilePageFocusedActivity.this,CommentsActivity.class);
                intent.putExtra("po_id",po_id);
                intent.putExtra("comments_02","0");
                intent.putExtra("parent","");
                intent.putExtra("fen_bian_id","");
                intent.putExtra("po_url",po_url);
                intent.putExtra("po_name",po_name);
                intent.putExtra("content",content);
                intent.putExtra("cus_logo",cus_logo);
                intent.putExtra("cus_name",cus_name);
                intent.putExtra("state",state);
                intent.putExtra("lCount",lCount);
                intent.putExtra("lstate",lstate);
                intent.putExtra("count",count);
                intent.putExtra("col",col);
                intent.putExtra("hits_like",hits_like);
                intent.putExtra("cus_id",cus_id);
                startActivity(intent);

                overridePendingTransition(R.anim.activity_anim_scenic_in,0);
                break;
            case R.id.activity_similar_profile_page_focused_bt_sand_commentaries: //发送
                String etCommentariesContent = activitySimilarProfilePageFocusedEtCommentariesContent.getText().toString().trim();
                if(!TextUtils.isEmpty(etCommentariesContent)){
                    String btCommentaries =  activitySimilarProfilePageFocusedBSandCommentaries.getText().toString().trim();
                    if(btCommentaries.equals("发送")){
                        submitComments(etCommentariesContent);
                    }else if(btCommentaries.equals("提交")){
                        submitRevert(id1,etCommentariesContent,po_id);
                    }

                }else{
                    Toast.makeText(SimilarProfilePageFocusedActivity.this,"请填写评论",Toast.LENGTH_SHORT).show();
                }

            break;
            case R.id.activity_similar_profile_page_focused_tv_attention: //关注
                String attention1 =  activitySimilarProfilePageFocusedTvAttention.getText().toString().trim();
                if(attention1.equals("关注")){
                    //添加关注
                    addAttentionPost(cus_id);
                }else if(attention1.equals("已关注")){
                    //取消关注
                    cancelAttentionPost(cus_id);
                }else if(attention1.equals("互相关注")){
                    //取消关注
                    cancelAttentionPost(cus_id);
                }
            break;
            case R.id.activity_similar_profile_page_focused_iv_right: //删除帖子
                PopupDialog();
            break;

        }
    }
    /**
     * @desc 弹出对话框
     * */
    private void PopupDialog() {
        dialog = new Dialog(this,R.style.ActionSheetDialogStyle);
        //填充对话框的布局
        inflate = LayoutInflater.from(this).inflate(R.layout.dialog_layout, null);
        //初始化控件
       /* choosePhoto = (TextView) inflate.findViewById(R.id.choosePhoto);
        takePhoto = (TextView) inflate.findViewById(R.id.takePhoto);
        choosePhoto.setOnClickListener(this);
        takePhoto.setOnClickListener(this);*/
        ImageView   iv_share_wechat = (ImageView) inflate.findViewById(R.id.dialog_layout_iv_share_wechat);
        ImageView   iv_share_qq = (ImageView) inflate.findViewById(R.id.dialog_layout_iv_share_qq);
        ImageView   iv_share_share_weibo = (ImageView) inflate.findViewById(R.id.dialog_layout_iv_share_share_weibo);
        ll_tip_off = (LinearLayout) inflate.findViewById(R.id.dialog_layout_ll_tip_off);
        ll_share = (LinearLayout) inflate.findViewById(R.id.dialog_layout_ll_share);
        LinearLayout   ll_delect = (LinearLayout) inflate.findViewById(R.id.dialog_layout_ll_delect);
        TextView   tv_cancel = (TextView) inflate.findViewById(R.id.dialog_layout_tv_cancel);
        iv_share_wechat.setOnClickListener(new View.OnClickListener() {  //微信
            @Override
            public void onClick(View v) {

            }
        });
        iv_share_qq.setOnClickListener(new View.OnClickListener() { //qq
            @Override
            public void onClick(View v) {

            }
        });
        iv_share_share_weibo.setOnClickListener(new View.OnClickListener() {  //w
            @Override
            public void onClick(View v) {

            }
        });

        ll_tip_off.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
                String user_id = sp.getString("user_id","");
                if(user_id.equals(cus_id)){
                    Toast.makeText(SimilarProfilePageFocusedActivity.this,"不能举报自己",Toast.LENGTH_LONG).show();
                }else{
                   // exposePost();
                    showDialog();
                    dialog.dismiss();

                }
            }
        });
        ll_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showShare();
            }
        });
        ll_delect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
                String user_id = sp.getString("user_id","");
                if(user_id.equals(cus_id)){
                    tipOffPost();
                }else{
                    Toast.makeText(SimilarProfilePageFocusedActivity.this,"不能删除别人的帖子",Toast.LENGTH_LONG).show();
                }

            }
        });
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        //将布局设置给Dialog
        dialog.setContentView(inflate);
        //获取当前Activity所在的窗体
        Window dialogWindow = dialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity( Gravity.BOTTOM);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.y = 20;//设置Dialog距离底部的距离
        //       将属性设置给窗体
        dialogWindow.setAttributes(lp);
        dialog.show();//显示对话框
    }
    /**
     * @desc 举报帖子
     * @param po_id
     * @param content*/
    private void exposePost(String po_id, String content) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.EXPOSE_POST)
                .addParams("po_id",po_id)
                .addParams("cus_id", user_id)
                .addParams("cat", content)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse =  response.body().string();
                        Log.e(TAG,"parseNetworkResponse========"+parseNetworkResponse);
                        Gson gson =  new Gson();
                        final ExposePostBean exposePostBean =   gson.fromJson(parseNetworkResponse,ExposePostBean.class);
                        if(exposePostBean.errorCode == 200){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,"举报成功",Toast.LENGTH_LONG).show();
                                }
                            });
                        }else{
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,exposePostBean.errorMessage,Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }

    /**
     * @desc 删除帖子
     * */
    private void tipOffPost() {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.DELET_POST)
                .addParams("po_id", po_id)
                .addParams("cus_id", user_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse =  response.body().string();
                        Log.e(TAG,"parseNetworkResponse========"+parseNetworkResponse);
                        Gson gson =  new Gson();
                        final TipOffPostBean tipOffPostBean =  gson.fromJson(parseNetworkResponse,TipOffPostBean.class);
                        if(tipOffPostBean.errorCode == 200){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,tipOffPostBean.errorMessage,Toast.LENGTH_LONG).show();
                                    dialog.dismiss();
                                }
                            });
                        }else if(tipOffPostBean.errorCode == 66){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,tipOffPostBean.errorMessage,Toast.LENGTH_LONG).show();
                                }
                            });
                        }else{
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,tipOffPostBean.errorMessage,Toast.LENGTH_LONG).show();
                                }
                            });
                        }
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }

    /**
     * @desc 取消关注帖子
     * @param */
    private void cancelAttentionPost(String cus_id) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.CANCLE_ATTENTION_POST)
                .addParams("cus_id",user_id)
                .addParams("followed", cus_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse =  response.body().string();
                       // Log.e(TAG,"parseNetworkResponse========"+parseNetworkResponse);
                        Gson gson =  new Gson();
                        final CancelAttentionPostBean cancelAttentionPostBean = gson.fromJson(parseNetworkResponse,CancelAttentionPostBean.class);
                        if(cancelAttentionPostBean.errorCode == 200){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,"取消关注成功",Toast.LENGTH_LONG).show();
                                    activitySimilarProfilePageFocusedTvAttention.setText("关注");

                                }
                            });
                        }else{
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,cancelAttentionPostBean.errorMessage,Toast.LENGTH_LONG).show();
                                }
                            });
                        }

                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }
    /**
     * @desc 添加关注帖子
     * @param */
    private void addAttentionPost(String cus_id) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.ADD_ATTENTION_POST)
                .addParams("cus_id", user_id)
                .addParams("followed",cus_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String parseNetworkResponse =  response.body().string();
                        //Log.e(TAG,"parseNetworkResponse========"+parseNetworkResponse);
                        Gson gson =  new Gson();
                        final AttentionPostBean attentionPostBean =  gson.fromJson(parseNetworkResponse,AttentionPostBean.class);
                        if(attentionPostBean.errorCode == 200){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,"关注成功",Toast.LENGTH_LONG).show();
                                  //  loadGuessYouLikeDate(1);
                                    activitySimilarProfilePageFocusedTvAttention.setText("已关注");

                                }
                            });
                        }else{
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,attentionPostBean.errorMessage,Toast.LENGTH_LONG).show();
                                }
                            });
                        }

                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }
    /**
     * @desc  收藏
     * */
    private void clickcollect() {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String  user_id = sp.getString("user_id","");
        Log.e(TAG,"activity_similar_profile_page_focused_sb_collect=====22=====收藏==>");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.COLLECT)
                .addParams("cus_id", user_id)
                .addParams("po_id", po_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                       // Log.e(TAG,"praiseParseNetworkResponse============>"+praiseParseNetworkResponse);
                        final ClickcollectBean clickcollectBean = gson.fromJson(praiseParseNetworkResponse,ClickcollectBean.class);
                        if(clickcollectBean.errorCode == 200 ){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,clickcollectBean.errorMessage,Toast.LENGTH_SHORT).show();

                                }
                            });
                        }else{
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,clickcollectBean.errorMessage,Toast.LENGTH_SHORT).show();
                                }
                            });
                        }

                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }

    /**
     * @desc 帖子评论
     * */
    private void initPostComments(int p, final String po_id) {
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.POST_COMMENTS)
                .addParams("po_id", po_id)
                .addParams("P", p+"")
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                        //Log.e(TAG,"praiseParseNetworkResponse============>"+praiseParseNetworkResponse);
                        final PostCommentsBean postCommentsBean =  gson.fromJson(praiseParseNetworkResponse,PostCommentsBean.class);
                        if(postCommentsBean.errorCode == 200 ){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    mlist = postCommentsBean.data;
                                    if(mlist != null){
                                        similarProfilePageFocusedAdapter = new SimilarProfilePageFocusedAdapter(SimilarProfilePageFocusedActivity.this);
                                        activitySimilarProfilePageFocusedEcyclerView.setAdapter(similarProfilePageFocusedAdapter);
                                        similarProfilePageFocusedAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
                                            @Override
                                            public void onItemClick(View view) {
                                                int position = activitySimilarProfilePageFocusedEcyclerView.getChildAdapterPosition(view);
                                                Intent intent2  =  new Intent(SimilarProfilePageFocusedActivity.this,AllCommentsActivity.class);
                                                intent2.putExtra("post_comments",mlist.get(position).id);
                                                intent2.putExtra("post_comments_name",mlist.get(position).cus_name);
                                                intent2.putExtra("post_comments_content",mlist.get(position).content);
                                                intent2.putExtra("post_comments_date",mlist.get(position).addtime);
                                                intent2.putExtra("post_comments_loge",mlist.get(position).cus_logo);
                                                intent2.putExtra("post_comments_id",mlist.get(position).id);
                                                intent2.putExtra("po_id",po_id);

                                                intent2.putExtra("po_url",po_url);
                                                intent2.putExtra("po_name",po_name);
                                                intent2.putExtra("content",content);
                                                intent2.putExtra("cus_logo",cus_logo);
                                                intent2.putExtra("cus_name",cus_name);
                                                intent2.putExtra("state",state);
                                                intent2.putExtra("lCount",lCount);
                                                intent2.putExtra("lstate",lstate);
                                                intent2.putExtra("count",count);
                                                intent2.putExtra("col",col);
                                                intent2.putExtra("hits_like",hits_like);
                                                intent2.putExtra("cus_id",cus_id);
                                                startActivity(intent2);


                                            }

                                            @Override
                                            public void onItemFirstButtonClick(View v, int position) {
                                               /* activitySimilarProfilePageFocusedLlIsVisition.setVisibility(View.GONE);
                                                activitySimilarProfilePageFocusedLlCommentaries.setVisibility(View.VISIBLE);
                                                id1 = mlist.get(position).id;
                                                // Toast.makeText(SimilarProfilePageFocusedActivity.this,"",Toast.LENGTH_LONG)
                                                activitySimilarProfilePageFocusedBSandCommentaries.setText("提交");*/

                                                Intent intent = new Intent(SimilarProfilePageFocusedActivity.this,CommentsActivity.class);
                                                intent.putExtra("po_id",po_id);
                                                intent.putExtra("comments_02","1");
                                                intent.putExtra("parent",mlist.get(position).id);
                                                Log.e(TAG,"parent============>"+mlist.get(position).id);
                                                intent.putExtra("fen_bian_id","0");
                                                intent.putExtra("po_url",po_url);
                                                intent.putExtra("po_name",po_name);
                                                intent.putExtra("content",content);
                                                intent.putExtra("cus_logo",cus_logo);
                                                intent.putExtra("cus_name",cus_name);
                                                intent.putExtra("state",state);
                                                intent.putExtra("lCount",lCount);
                                                intent.putExtra("lstate",lstate);
                                                intent.putExtra("count",count);
                                                intent.putExtra("col",col);
                                                intent.putExtra("hits_like",hits_like);
                                                intent.putExtra("cus_id",cus_id);
                                                startActivity(intent);
                                                overridePendingTransition(R.anim.activity_anim_scenic_in,0);
                                               // overridePendingTransition(R.anim.activity_anim_scenic_in, R.anim.activity_anim_scenic_out);
                                               // finish();
                                            }
                                        });

                                    }else{
                                        Toast.makeText(SimilarProfilePageFocusedActivity.this,"评论为空",Toast.LENGTH_SHORT).show();
                                    }

                                }
                            });
                        }else {
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,postCommentsBean.errorMessage,Toast.LENGTH_SHORT).show();
                                }
                            });
                        }



                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }
    /**
     * @desc 回复
     * */
    private void submitRevert(String id1, String etCommentariesContent, String po_id_01) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String  user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.COMMENTS)
                .addParams("parent",id1)
                .addParams("po_id", po_id_01)
                .addParams("content", etCommentariesContent)
                .addParams("cus_id", user_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                       // Log.e(TAG,"praiseParseNetworkResponse============>"+praiseParseNetworkResponse);
                        final PraiseBean praiseBean = gson.fromJson(praiseParseNetworkResponse,PraiseBean.class);
                        if(praiseBean.errorCode == 200){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,"回复成功",Toast.LENGTH_SHORT).show();
                                    activitySimilarProfilePageFocusedLlIsVisition.setVisibility(View.VISIBLE);
                                    activitySimilarProfilePageFocusedLlCommentaries.setVisibility(View.GONE);
                                   initPostComments(1, po_id);

                                }
                            });
                        }else{
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,praiseBean.errorMessage,Toast.LENGTH_SHORT).show();
                                    activitySimilarProfilePageFocusedLlIsVisition.setVisibility(View.VISIBLE);
                                    activitySimilarProfilePageFocusedLlCommentaries.setVisibility(View.GONE);
                                }
                            });
                        }

                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }

    /**
     * @desc 点赞   {"errorCode":"200","errorMessage":"点赞成功!"}
     * */
    private void submitPraise() {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String  user_id = sp.getString("user_id","");
      //  Log.e(TAG,"activity_similar_profile_page_focused_sb_praise=======11===点赞==>");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.PRAISE)
                .addParams("cus_id", user_id)
                .addParams("po_id", po_id)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                       // Log.e(TAG,"praiseParseNetworkResponse============>"+praiseParseNetworkResponse);
                        final PraiseBean praiseBean = gson.fromJson(praiseParseNetworkResponse,PraiseBean.class);
                        if(praiseBean.errorCode == 200){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,"点赞成功",Toast.LENGTH_SHORT).show();
                                }
                            });
                        }else{
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,praiseBean.errorMessage,Toast.LENGTH_SHORT).show();
                                }
                            });
                        }
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });

    }

    /**
     * @desc 评论  {"errorCode":200,"errorMessage":"ok"}
     * @param etCommentariesContent*/
    private void submitComments(String etCommentariesContent) {
        SharedPreferences sp = getSharedPreferences("second_app_internal_data", 0);
        String  user_id = sp.getString("user_id","");
        OkHttpUtils
                .post()
                .url(RBConstants.SERVER_URL+RBConstants.COMMENTS)
                .addParams("cus_id", user_id)
                .addParams("po_id", po_id)
                .addParams("content", etCommentariesContent)
                .build()
                .execute(new Callback() {
                    @Override
                    public Object parseNetworkResponse(Response response, int id) throws Exception {
                        String praiseParseNetworkResponse =  response.body().string();
                        Gson gson = new Gson();
                       // Log.e(TAG,"praiseParseNetworkResponse============>"+praiseParseNetworkResponse);
                        final CommentsBean commentsBean = gson.fromJson(praiseParseNetworkResponse,CommentsBean.class);
                        if(commentsBean.errorCode == 200 ){
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,"评论成功",Toast.LENGTH_SHORT).show();
                                    activitySimilarProfilePageFocusedLlIsVisition.setVisibility(View.VISIBLE);
                                    activitySimilarProfilePageFocusedLlCommentaries.setVisibility(View.GONE);
                                    initPostComments(1,po_id);
                                    intent_01 ++;
                                    activitySimilarProfilePageFocusedTvCommentsBumber.setText(intent_01+"");
                                }
                            });
                        }else{
                            MyApplication.getmHandler().post(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(SimilarProfilePageFocusedActivity.this,commentsBean.errorMessage,Toast.LENGTH_SHORT).show();
                                    activitySimilarProfilePageFocusedLlIsVisition.setVisibility(View.VISIBLE);
                                    activitySimilarProfilePageFocusedLlCommentaries.setVisibility(View.GONE);
                                }
                            });
                        }
                        return null;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(Object response, int id) {

                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 移除所有的粘性事件.
        EventBus.getDefault().removeAllStickyEvents();
    }
}
